<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>受试者招募系统</title>
    <link type="text/css" href="${pageContext.request.contextPath}/assets/css/layout.css" rel="stylesheet" />
    <link type="text/css" href="${pageContext.request.contextPath}/assets/css/style.css" rel="stylesheet" />
    <link type="text/css" href="${pageContext.request.contextPath}/assets/plugins/jquery-easyui-1.4.2/themes/metro/easyui.css" rel="stylesheet" />
	<link type="text/css" href="${pageContext.request.contextPath}/assets/plugins/jquery-easyui-1.4.2/themes/mobile.css" rel="stylesheet" />
	<link type="text/css" href="${pageContext.request.contextPath}/assets/css/common.css" rel="stylesheet" />
	<style type="text/css">
	.dd_content{
		padding-top:20px;
	}
	.dd_content .dd_row{
		padding:10px;
	}
	.dd_content .dd_row label{
		display:inline-block;
		width:100px;
		text-align:right;
	}
	.info i:hover{
		cursor:pointer;
	}
	.logo{
		margin-left:-10px;
	}
	</style>
</head>
<body>
    <div class="main-top">
        <a class="icon_menu"></a>
        <div class="main-nav">
            <ul></ul>
        </div>
        <div class="nav-right">
            <div class="info">
                <i></i>
                <span></span>
            </div>
            <div class="option">
                <i></i>
                <div class="drop-wrap">
                    <div class="arrow"></div>
                    <ul class="item">
                        <li>
                            <a onclick="showUserInfo()">个人中心</a>
                        </li>
                        <li>
                            <a onclick="modifyPassword()">修改密码</a>
                        </li>
                        <li>
                            <a href="${pageContext.request.contextPath}/bg/login.do">注销登录</a>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
    <div class="main-left">
        <h1 class="logo"></h1> 
        <div id="sidebar-nav" class="sidebar-nav">
        </div>
    </div>
    <div class="main-container">
        <!--iframe中起作用的是name字段-->
        <iframe id="ifr" name="ifr" frameborder="0" src="${pageContext.request.contextPath}/bg/home.do">
        </iframe>
    </div>
    
    <!-- 修改密码弹出框 -->
    <div id="dd" style="width:500px;height:400px;">
		<div class="dd_content">
		  <div class="dd_row">
		   		<label>用户名：</label>
		  		<input id="user_name" style="height: 32px;" disabled="disabled" class="input normal"></input>
		  </div>
		  <div class="dd_row">
		   		<label>原密码：</label>
		  		<input id="password" type="password" style="height: 32px;" class="input normal"></input>
		  </div>
		  <div class="dd_row">
		     	<label>新密码：</label>
		        <input id="password_new" type="password" style="height: 32px;" class="input normal"></input>
		  </div>
          <div class="dd_row">
                <label>确认密码：</label>
		        <input id="password_new_confirm" type="password" style="height: 32px;" class="input normal"></input>
          </div>

		</div>
		<div style="position:absolute;bottom:20px;padding-left:330px;">
		  <button class="btn" onclick="savePassword()">提交保存</button>
		  <button class="btn yellow" onclick="cancelModifyPassword()">取消</button>
		</div>
	</div>
    
    <input id="contextPath" type="hidden" value="{request.getContextPath()}" />
    <input id="code" type="hidden" value="${code}" />
    <script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath}/assets/js/jquery-1.11.2.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath}/assets/js/common.js"></script>
    <script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath}/assets/js/layindex.js"></script>
	<script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath}/assets/plugins/jquery-easyui-1.4.2/jquery.easyui.min.js"></script>
	<script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath}/assets/plugins/jquery-easyui-1.4.2/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript">
    var contextPath = "<%=request.getContextPath()%>";
    var user_code=$("#code").val();
    var user;//用户
  	$(function(){
  		queryUserInfo();
        $('#dd').dialog({
            closed: true,
            title: '修改密码'
        });
    })  
    //查询用户信息
    function queryUserInfo(){
  		var param={
  				CODE:user_code,
  				rnd:Math.random()
  		}
		$.ajax({
			url : contextPath + "/bg/U104.do",
			data : param,
			dataType : 'json',
			success : function(data, textStatus, jqXHR) {	
				if(data.status=='true'){
					user=data.record;
					$('.info span').html(user.NAME);
				}else{
					$.messager.alert('失败','查询用户失败！');
					location.href=contextPath+"/bg/login.do";
				}
			},
			error : function(jqXHR, textStatus, errorThrown) {
				$.messager.alert('失败','查询用户失败！');
				location.href=contextPath+"/bg/login.do";
			}
		});
  	}
  	//修改密码
  	function modifyPassword(){
		$('#user_name').val(user.NAME);
		$('#dd').dialog('open');		
  	}
  	//取消修改密码
  	function cancelModifyPassword(){
  		$('#dd').dialog('close');
  	}
  	//提交保存（修改密码）
  	function savePassword(){
  		var password=$('#password').val();
  		if($.isNullOrEmpty(password)){
  			$.messager.show({
  				title:'提示',
  				msg:'原密码不能为空！',
  				showType:'slide'
  			});
  			$('#password').focus();
  			return;
  		}
  		var password_new=$('#password_new').val();
  		if($.isNullOrEmpty(password_new)){
  			$.messager.show({
  				title:'提示',
  				msg:'新密码不能为空！',
  				showType:'slide'
  			});
  			$('#password_new').focus();
  			return;
  		}
  		var password_new_confirm=$('#password_new_confirm').val();
  		if($.isNullOrEmpty(password_new_confirm)){
  			$.messager.show({
  				title:'提示',
  				msg:'确认密码不能为空！',
  				showType:'slide'
  			});
  			$('#password_new_confirm').focus();
  			return;
  		}
  		if(password_new!=password_new_confirm){
  			$.messager.show({
  				title:'提示',
  				msg:'新密码与确认密码不符，请重新输入！',
  				showType:'slide'
  			});
  			$('#password_new_confirm').focus();
  			return;
  		}
  		//用户校验
		if(password!=user.PASSWORD){
  			$.messager.show({
  				title:'提示',
  				msg:'原密码输入错误，请重新输入！',
  				showType:'slide'
  			});
  			$('#password').focus();
  			return;
		}

  		var param={
  				CODE:user_code,
  				PASSWORD:password_new,
  				rnd:Math.random()
  		}
		$.ajax({
			url : contextPath + "/bg/U107.do",
			data : param,
			dataType : 'json',
			success : function(data, textStatus, jqXHR) {	
				if(data.status=='true'){
				    $.messager.confirm('确认', '用户密码修改成功，是否重新登陆?', function(r){
				    	if (r){
				    		location.href=contextPath+"/bg/login.do";
				    	}else{
				    		$('#dd').dialog('close');
				    	}
				    });
				}else{
					$.messager.alert('失败','用户密码修改失败！');
				}
			},
			error : function(jqXHR, textStatus, errorThrown) {
				$.messager.alert('失败','用户密码修改失败！');
			}
		});
  		
  	}
  	//查看用户信息
  	function showUserInfo(){
  		var url = contextPath+ "/bg/user_edit.do?action=edit&userId=" + user_code + "&rnd="+ Math.random();
  		$('#ifr').attr("src",url);
  	}
    </script>
</body>
</html>